home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / debuging.dos < prev    next >
Text File  |  1996-04-08  |  3KB  |  109 lines

  1. #line 2 "osdep/debuging.dos"
  2. #ifdef DEBUG
  3. /*----------------------------------------------------------------------
  4.      Initialize debugging - open the debug log file
  5.  
  6.   Args: none
  7.  
  8.  Result: opens the debug logfile for dprints
  9.   ----*/
  10. void
  11. init_debug()
  12. {
  13.     char filename[MAXPATH+1];
  14.  
  15.     if(!debug)
  16.       return;
  17.  
  18.     /*
  19.      * we can't assume anything about root or home dirs, so
  20.      * just plunk it down in the same place as the pinerc
  21.      */
  22.     
  23.     if(ps_global->pinerc)
  24.       sprintf(filename, "%.*s%s",
  25.           last_cmpnt(ps_global->pinerc) - ps_global->pinerc,
  26.           ps_global->pinerc, DEBUGFILE);
  27.     else if(getenv("HOME"))
  28.       build_path(filename, ps_global->home_dir, DEBUGFILE);
  29.     else
  30.       strcpy(filename, DEBUGFILE);
  31.  
  32.     unlink(filename);
  33.  
  34.     debugfile = fopen(filename, "w");
  35.     if(debugfile != NULL){
  36.     time_t now = time((time_t *)0);
  37.     if(debug > 7)
  38.       setbuf(debugfile, NULL);
  39.     dprint(1, (debugfile, "Debug output of the Pine program (at debug"));
  40.     dprint(1, (debugfile, " level %d).  Version %s\n%s\n",
  41.           debug, pine_version, ctime(&now)));
  42.     }
  43. }
  44.  
  45.  
  46. void
  47. save_debug_on_crash(dfile)
  48. FILE *dfile;
  49. {
  50.     char *crashname = CRASHFILE;
  51.     char *filename = DEBUGFILE;
  52.     int status;
  53.     char msg[256];
  54.     time_t now = time((time_t *)0);
  55.  
  56.     fprintf(dfile, "\nsave_debug_on_crash: Version %s: debug level %d\n",
  57.     pine_version, debug);
  58.     fprintf(dfile, "\n                   : %s\n", ctime(&now));
  59.     fprintf(dfile, "\nAttempting to save debug file to %s\n", crashname);
  60.  
  61.     fclose(dfile);
  62.  
  63.     unlink (crashname);
  64.     status = rename (filename, crashname);
  65.  
  66. #ifdef _WINDOWS
  67.     sprintf (msg, "Pine debugging information saved in file:  %s",
  68.         status == 0 ? crashname : filename);
  69.     mswin_messagebox (msg, 0);
  70. #endif
  71. }
  72.  
  73.  
  74. #define CHECK_EVERY_N_TIMES 100
  75. #define MAX_DEBUG_FILE_SIZE 200000L
  76. /*
  77.  * This is just to catch runaway Pines that are looping spewing out
  78.  * debugging (and filling up a file system).  The stop doesn't have to be
  79.  * at all precise, just soon enough to hopefully prevent filling the
  80.  * file system.  If the debugging level is high (9 for now), then we're
  81.  * presumably looking for some problem, so don't truncate.
  82.  */
  83. int
  84. do_debug(debug_fp)
  85. FILE *debug_fp;
  86. {
  87.     static int counter = CHECK_EVERY_N_TIMES;
  88.     static int ok = 1;
  89.     long filesize;
  90.  
  91.     if(debug < 9 && ok && --counter <= 0){
  92.     if((filesize = fp_file_size(debug_fp)) != -1L)
  93.       ok = (unsigned long)filesize < (unsigned long)MAX_DEBUG_FILE_SIZE;
  94.  
  95.     counter = CHECK_EVERY_N_TIMES;
  96.     if(!ok){
  97.         fprintf(debug_fp, "\n\n --- No more debugging ---\n");
  98.         fprintf(debug_fp,
  99.         "     (debug file growing too large - over %ld bytes)\n\n",
  100.         MAX_DEBUG_FILE_SIZE);
  101.         fflush(debug_fp);
  102.     }
  103.     }
  104.     return(ok);
  105. }
  106. #endif /* DEBUG */
  107.  
  108.  
  109.